﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace WindowsFormsApp4
{
   public  class DbHeper
    {
        private static readonly string conString = "server=.;database=Blogs;uid=sa;pwd=123456";
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection connection = new SqlConnection(conString);
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connection);

            DataTable dt = new DataTable();

            connection.Open();

            dataAdapter.Fill(dt);

            return dt;
            
        }

        //增加或修改
        public static int AddOrUpdataDelete(string sql)
        {
            SqlConnection connection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql, connection);

            connection.Open();

            return command.ExecuteNonQuery();
        }

    }
}
